package com.nine.pesys.model.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * User类，人员基本类
 * Created by L先森 on 2014/12/20.
 */
@Entity
@Table(name = "tb_user")
public class User implements Serializable {
    private Long id;
    private String name;
    private String password;
    private String stuNumber;
    private String phoneNum;
    private String email;
    private String gender;
    private Set<Role> roles = new HashSet<Role>();
    private Set<EquipmentImformation>  equipmentImformation = new HashSet<EquipmentImformation>();
    private Set<FileInformation> fileInformation = new HashSet<FileInformation>();
    private Set<Game> game = new HashSet<Game>();

    @Id
    @Column(name = "id",length = 10)
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Column
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column
    public String getStuNumber() {
        return stuNumber;
    }

    public void setStuNumber(String stuNumber) {
        this.stuNumber = stuNumber;
    }

    @Column
    public String getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    @ManyToMany(fetch = FetchType.LAZY,cascade={CascadeType.MERGE,CascadeType.PERSIST})
    @JoinTable(name = "tb_user_role", joinColumns = { @JoinColumn(name = "userId") }, inverseJoinColumns = { @JoinColumn(name = "roleId") })
    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "userId")
    public Set<EquipmentImformation> getEquipmentImformation() {
        return equipmentImformation;
    }

    public void setEquipmentImformation(Set<EquipmentImformation> equipmentImformation) {
        this.equipmentImformation = equipmentImformation;
    }

    @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "userId")
    public Set<FileInformation> getFileInformation() {
        return fileInformation;
    }

    public void setFileInformation(Set<FileInformation> fileInformation) {
        this.fileInformation = fileInformation;
    }

    @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name = "userId")
    public Set<Game> getGame() {
        return game;
    }

    public void setGame(Set<Game> game) {
        this.game = game;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", stuNumber='" + stuNumber + '\'' +
                ", phoneNum='" + phoneNum + '\'' +
                ", email='" + email + '\'' +
                ", gender='" + gender + '\'' +
                ", roles=" + roles +
                ", equipmentImformation=" + equipmentImformation +
                ", fileInformation=" + fileInformation +
                ", game=" + game +
                '}';
    }
}
